Skip to content

chore: ruff lint 接入 + factory 同步 36a8749c + 版本 0.2.1 - #50

Merged
im47cn merged 4 commits into
mainfrom
chore/release-0.2.1
Nov 18, 2026
Merged

im47cn merged 4 commits into
mainfrom
chore/release-0.2.1

Conversation

@im47cn

@im47cn im47cn commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

内容

  • ci: 接入 ruff 静态检查(0.17.3 钉版,E4/E7/E9/F 真实错误集)+ 清理未用导入
  • fix: commitlint 配置改 .cjs(上层 package.json type:module 导致 config 加载崩溃),钩子脚本同步
  • chore: factory 同步上游 36a8749c + lease-fresh 参数校验 + 锁 pid 写入 fail-closed
  • chore: 版本 0.2.1(patch:无 API 变化,api-snapshot 零漂移)

本地门禁

  • ruff check ✅ / pytest + cov 98.63% ≥ 98% ✅ / api snapshot 零漂移 ✅ / factory tests 549 passed ✅
  • sourcery-gate:本机 CLI 免费 tier 无法运行 review --check(账户限制,非代码问题)

Sourcery 摘要

改进 lint 检查和锁安全检查,同时更新项目工具、工厂元数据和补丁版本。

Bug 修复:

  • 防止租约有效性检查将缺少锁路径参数的情况误判为锁已失效。
  • 如果锁 PID 持久化失败,则采取拒绝访问的默认策略,避免出现不安全的并发所有权。

增强:

  • 为核心错误检查添加固定版本的 Ruff lint 检查,并清理未使用的导入。
  • 将 commitlint 配置保留为 CommonJS 格式,以兼容模块配置。
  • 根据上游变更同步工厂元数据。

构建:

  • 根据项目支持的检查项和排除项配置 Ruff。

CI:

  • 添加一个运行固定版本 Ruff 检查的 GitHub Actions 任务。

测试:

  • 针对无效租约参数和锁 PID 写入失败的情况添加回归测试。

杂项:

  • 将软件包版本升级至 0.2.1,同时保持公共 API 快照不变。
Original summary in English

Summary by Sourcery

Improve linting and lock-safety checks while updating project tooling, factory metadata, and the patch version.

Bug Fixes:

  • Prevent lease freshness checks from treating missing lock-path arguments as a dead lock.
  • Fail closed when lock PID persistence fails to avoid unsafe concurrent ownership.

Enhancements:

  • Add pinned Ruff linting for core error checks and clean up unused imports.
  • Preserve the commitlint configuration under CommonJS for compatibility with the module configuration.
  • Synchronize the factory metadata with upstream changes.

Build:

  • Configure Ruff with the project’s supported checks and exclusions.

CI:

  • Add a GitHub Actions job running the pinned Ruff check.

Tests:

  • Add regression coverage for invalid lease arguments and lock PID write failures.

Chores:

  • Bump the package version to 0.2.1 without changing the public API snapshot.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f152ad7e-1014-4130-a1dc-aed075471e5b
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

审查者指南

实现

从 SDK 模块中移除未使用的导入,并保留通过通配符导出的 List 别名,同时为其屏蔽 Ruff 检查。

  • src/wop_sdk/config/_loader.py L9
  • src/wop_sdk/config/_parser.py L7
  • src/wop_sdk/transport_discovery.py L7

配置

配置固定的 Ruff lint 检查集,并将其添加为 CI 检查。

  • .github/workflows/ci.yml L152-165
  • pyproject.toml L67-79

将 commitlint 配置重命名为 CommonJS 格式,并更新钩子,使其检查并引用重命名后的文件。

  • .lefthook/commitmsg-check.sh L4, L37-38
  • commitlint.config.cjs

将软件包版本升级至 0.2.1。

  • pyproject.toml L7

测试

在清理 Ruff 相关问题时,从现有 SDK 测试中移除未使用的导入。

  • tests/test_config.py L6(已移除的行)、L8(已移除的行)、L12
  • tests/test_suites.py L6
  • tests/test_bdd.py L13(已移除的行)
  • tests/test_config_loading.py L8(已移除的行)

添加回归测试,覆盖缺少 lease-fresh 参数的情况,以及写入 hosting 锁 PID 失败时的失败关闭行为。

  • .factory/tests/test_factory_lib.py L624-633
  • .factory/tests/test_hosting.py L1126-1147

锁文件与供应商代码

将供应商提供的 factory 文件与上游同步,包括 lease-fresh 的参数验证,以及锁 PID 写入错误时的失败关闭处理。

  • .factory/factory_lib.py L1447-1449
  • .factory/hosting.py L1100-1110

在本地配置和上游锁元数据中记录已同步的 factory 状态。

  • .factory/factory-local.json L38-39
  • .factory/upstream-lock.json L2-4

提示与命令

与 Sourcery 互动

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论创建 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以在审查评论中回复 @sourcery-ai issue,以此创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以便随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以便随时(重新)生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你想从头开始进行新的审查,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义使用体验

访问你的仪表板,以便:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implementation

Remove unused imports from SDK modules and preserve the wildcard-exported List alias while silencing Ruff for it.

  • src/wop_sdk/config/_loader.py L9
  • src/wop_sdk/config/_parser.py L7
  • src/wop_sdk/transport_discovery.py L7

Configuration

Configure the pinned Ruff lint set and add it as a CI check.

  • .github/workflows/ci.yml L152-165
  • pyproject.toml L67-79

Rename the commitlint configuration to CommonJS and update the hook to check and reference the renamed file.

  • .lefthook/commitmsg-check.sh L4, L37-38
  • commitlint.config.cjs

Bump the package version to 0.2.1.

  • pyproject.toml L7

Tests

Remove unused imports from existing SDK tests as part of the Ruff cleanup.

  • tests/test_config.py L6 (removed lines), L8 (removed lines), L12
  • tests/test_suites.py L6
  • tests/test_bdd.py L13 (removed lines)
  • tests/test_config_loading.py L8 (removed lines)

Add regression coverage for missing lease-fresh arguments and fail-closed behavior when writing a hosting lock PID fails.

  • .factory/tests/test_factory_lib.py L624-633
  • .factory/tests/test_hosting.py L1126-1147

Lock files and vendored code

Sync the vendored factory files with upstream, including argument validation for lease-fresh and fail-closed handling of lock PID write errors.

  • .factory/factory_lib.py L1447-1449
  • .factory/hosting.py L1100-1110

Record the synchronized factory state in its local configuration and upstream lock metadata.

  • .factory/factory-local.json L38-39
  • .factory/upstream-lock.json L2-4

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 07087f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@im47cn
im47cn enabled auto-merge November 18, 2026 09:13
@im47cn
im47cn merged commit 32efa94 into main Nov 18, 2026
23 checks passed
@im47cn
im47cn deleted the chore/release-0.2.1 branch November 18, 2026 09:13

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 3 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".factory/hosting.py" line_range="1106" />
<code_context>
                 fh.write(str(os.getpid()))
+        except OSError as e:
+            # 无 pid 残锁会被判陈旧致另一进程接管(双写):释放并拒持锁
+            shutil.rmtree(lock_dir, ignore_errors=True)
+            raise HostingError(
+                f"add {name}: 锁 pid 写入失败({e}),fail-closed 拒持锁",
</code_context>
<issue_to_address>
**Replacement lock gets deleted**

When pid-file creation or writing fails after the pid-less directory outlives the stale-lock grace period and another caller reclaims it, the OSError handler calls `shutil.rmtree(lock_dir)` by pathname without verifying ownership, deleting the replacement owner's active lock; another caller then enters the critical section and can post a duplicate label.

Remove `lock_dir` only after verifying it is still the lock directory created by this writer.
</issue_to_address>

### Comment 2
<location path=".github/workflows/ci.yml" line_range="155" />
<code_context>
+
+  # ruff 静态检查(E4/E7/E9/F;配置见 pyproject.toml [tool.ruff],vendored .factory
+  # 已排除)。版本锁定保证检查集稳定;纯静态、秒级。
+  lint:
+    runs-on: ubuntu-latest
+    steps:
</code_context>
<issue_to_address>
**Lint failures go untracked**

When the lint job fails while `test` and `oldest-deps` pass, `notify-failure` and `notify-recovery` do not depend on the lint job, so the failure goes untracked and the recovery job can close an existing failure issue while the workflow is red.

Include the lint job in the dependencies of both `notify-failure` and `notify-recovery`.
</issue_to_address>

### Comment 3
<location path=".factory/factory_lib.py" line_range="1447-1449" />
<code_context>
         # 不可读/内容畸形 = 死(SIGKILL 残锁过期同判)。退出码 0=活 1=死
         # 2=参数错。PG 形态(SUPABASE_DB)租约在库中,调用方不得用本
         # 命令的输出断言死活(保守 unknown)。
+        if len(argv) < 3:
+            print("lease-fresh: 缺锁文件路径参数", file=sys.stderr)
+            return 2
         lock = Path(argv[2])
         try:
</code_context>
<issue_to_address>
**Extra lease arguments look valid**

When the `lease-fresh` command is called with a lock path and one or more extra arguments, `main` reads only `argv[2]` and ignores remaining arguments, so a malformed invocation returns the lock’s live/dead status instead of the documented parameter-error status 2; a caller can mistake the result for a valid lease check.

Require exactly one lock-path argument and return 2 for any other argument count.
</issue_to_address>

Sourcery 评估

待批准。 请先处理 3 项发现。

阻塞性发现:.factory/hosting.py:1106、.github/workflows/ci.yml:155、.factory/factory_lib.py:1449


Sourcery 对开源项目免费——如果您喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".factory/hosting.py" line_range="1106" />
<code_context>
                 fh.write(str(os.getpid()))
+        except OSError as e:
+            # 无 pid 残锁会被判陈旧致另一进程接管(双写):释放并拒持锁
+            shutil.rmtree(lock_dir, ignore_errors=True)
+            raise HostingError(
+                f"add {name}: 锁 pid 写入失败({e}),fail-closed 拒持锁",
</code_context>
<issue_to_address>
**Replacement lock gets deleted**

When pid-file creation or writing fails after the pid-less directory outlives the stale-lock grace period and another caller reclaims it, the OSError handler calls `shutil.rmtree(lock_dir)` by pathname without verifying ownership, deleting the replacement owner's active lock; another caller then enters the critical section and can post a duplicate label.

Remove `lock_dir` only after verifying it is still the lock directory created by this writer.
</issue_to_address>

### Comment 2
<location path=".github/workflows/ci.yml" line_range="155" />
<code_context>
+
+  # ruff 静态检查(E4/E7/E9/F;配置见 pyproject.toml [tool.ruff],vendored .factory
+  # 已排除)。版本锁定保证检查集稳定;纯静态、秒级。
+  lint:
+    runs-on: ubuntu-latest
+    steps:
</code_context>
<issue_to_address>
**Lint failures go untracked**

When the lint job fails while `test` and `oldest-deps` pass, `notify-failure` and `notify-recovery` do not depend on the lint job, so the failure goes untracked and the recovery job can close an existing failure issue while the workflow is red.

Include the lint job in the dependencies of both `notify-failure` and `notify-recovery`.
</issue_to_address>

### Comment 3
<location path=".factory/factory_lib.py" line_range="1447-1449" />
<code_context>
         # 不可读/内容畸形 = 死(SIGKILL 残锁过期同判)。退出码 0=活 1=死
         # 2=参数错。PG 形态(SUPABASE_DB)租约在库中,调用方不得用本
         # 命令的输出断言死活(保守 unknown)。
+        if len(argv) < 3:
+            print("lease-fresh: 缺锁文件路径参数", file=sys.stderr)
+            return 2
         lock = Path(argv[2])
         try:
</code_context>
<issue_to_address>
**Extra lease arguments look valid**

When the `lease-fresh` command is called with a lock path and one or more extra arguments, `main` reads only `argv[2]` and ignores remaining arguments, so a malformed invocation returns the lock’s live/dead status instead of the documented parameter-error status 2; a caller can mistake the result for a valid lease check.

Require exactly one lock-path argument and return 2 for any other argument count.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: .factory/hosting.py:1106, .github/workflows/ci.yml:155, .factory/factory_lib.py:1449


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .factory/hosting.py
fh.write(str(os.getpid()))
except OSError as e:
# 无 pid 残锁会被判陈旧致另一进程接管(双写):释放并拒持锁
shutil.rmtree(lock_dir, ignore_errors=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 高 · 替换后的锁被删除

如果 pid 文件创建或写入失败,而不含 pid 的目录在陈旧锁宽限期过后仍然存在,并且另一个调用者重新获取了该锁,OSError 处理程序就会按路径调用 shutil.rmtree(lock_dir),却不验证所有权,从而删除新所有者正在使用的锁;随后另一个调用者会进入临界区,并可能发布重复标签。

只有在确认 lock_dir 仍是此写入者创建的锁目录后,才将其删除。

面向 AI 代理的提示
在 `.factory/hosting.py` 第 1106 行:

**替换后的锁被删除**

如果 pid 文件创建或写入失败,而不含 pid 的目录在陈旧锁宽限期过后仍然存在,并且另一个调用者重新获取了该锁,OSError 处理程序就会按路径调用 `shutil.rmtree(lock_dir)`,却不验证所有权,从而删除新所有者正在使用的锁;随后另一个调用者会进入临界区,并可能发布重复标签。

只有在确认 `lock_dir` 仍是此写入者创建的锁目录后,才将其删除。
Original comment in English

🟠 High · Replacement lock gets deleted

When pid-file creation or writing fails after the pid-less directory outlives the stale-lock grace period and another caller reclaims it, the OSError handler calls shutil.rmtree(lock_dir) by pathname without verifying ownership, deleting the replacement owner's active lock; another caller then enters the critical section and can post a duplicate label.

Remove lock_dir only after verifying it is still the lock directory created by this writer.

Prompt for AI agents
In `.factory/hosting.py` at line 1106:

**Replacement lock gets deleted**

When pid-file creation or writing fails after the pid-less directory outlives the stale-lock grace period and another caller reclaims it, the OSError handler calls `shutil.rmtree(lock_dir)` by pathname without verifying ownership, deleting the replacement owner's active lock; another caller then enters the critical section and can post a duplicate label.

Remove `lock_dir` only after verifying it is still the lock directory created by this writer.

Comment thread .github/workflows/ci.yml

# ruff 静态检查(E4/E7/E9/F;配置见 pyproject.toml [tool.ruff],vendored .factory
# 已排除)。版本锁定保证检查集稳定;纯静态、秒级。
lint:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · Lint 失败未被追踪

当 lint 任务失败,而 test 和 oldest-deps 通过时,notify-failure 和 notify-recovery 都不依赖 lint 任务,因此这次失败不会被追踪;即使工作流处于失败状态,恢复任务仍可能关闭现有的失败问题单。

将 lint 任务加入 notify-failure 和 notify-recovery 两者的依赖项中。

面向 AI 代理的提示
在 `.github/workflows/ci.yml` 第 155 行:

**Lint 失败未被追踪**

当 lint 任务失败,而 `test` 和 `oldest-deps` 通过时,`notify-failure` 和 `notify-recovery` 都不依赖 lint 任务,因此这次失败不会被追踪;即使工作流处于失败状态,恢复任务仍可能关闭现有的失败问题单。

将 lint 任务加入 `notify-failure` 和 `notify-recovery` 两者的依赖项中。
Original comment in English

🟡 Medium · Lint failures go untracked

When the lint job fails while test and oldest-deps pass, notify-failure and notify-recovery do not depend on the lint job, so the failure goes untracked and the recovery job can close an existing failure issue while the workflow is red.

Include the lint job in the dependencies of both notify-failure and notify-recovery.

Prompt for AI agents
In `.github/workflows/ci.yml` at line 155:

**Lint failures go untracked**

When the lint job fails while `test` and `oldest-deps` pass, `notify-failure` and `notify-recovery` do not depend on the lint job, so the failure goes untracked and the recovery job can close an existing failure issue while the workflow is red.

Include the lint job in the dependencies of both `notify-failure` and `notify-recovery`.

Comment thread .factory/factory_lib.py
Comment on lines +1447 to +1449
if len(argv) < 3:
print("lease-fresh: 缺锁文件路径参数", file=sys.stderr)
return 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 多余的租约参数看起来有效

当 lease-fresh 命令接收到锁路径以及一个或多个额外参数时,main 只读取 argv[2] 并忽略其余参数,因此格式错误的调用会返回锁的存活/失效状态,而不是文档规定的参数错误状态码 2;调用方可能会误以为这是有效的租约检查结果。

要求恰好提供一个锁路径参数,其他任何参数数量都返回 2。

面向 AI 代理的提示
在 `.factory/factory_lib.py` 第 1447–1449 行:

**多余的租约参数看起来有效**

当 `lease-fresh` 命令接收到锁路径以及一个或多个额外参数时,`main` 只读取 `argv[2]` 并忽略其余参数,因此格式错误的调用会返回锁的存活/失效状态,而不是文档规定的参数错误状态码 2;调用方可能会误以为这是有效的租约检查结果。

要求恰好提供一个锁路径参数,其他任何参数数量都返回 2。
Original comment in English

🟡 Medium · Extra lease arguments look valid

When the lease-fresh command is called with a lock path and one or more extra arguments, main reads only argv[2] and ignores remaining arguments, so a malformed invocation returns the lock’s live/dead status instead of the documented parameter-error status 2; a caller can mistake the result for a valid lease check.

Require exactly one lock-path argument and return 2 for any other argument count.

Prompt for AI agents
In `.factory/factory_lib.py` at lines 1447-1449:

**Extra lease arguments look valid**

When the `lease-fresh` command is called with a lock path and one or more extra arguments, `main` reads only `argv[2]` and ignores remaining arguments, so a malformed invocation returns the lock’s live/dead status instead of the documented parameter-error status 2; a caller can mistake the result for a valid lease check.

Require exactly one lock-path argument and return 2 for any other argument count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants